import 'package:flutter/material.dart';
import 'package:provide/provide.dart';
import 'package:study_flutter/yzhg/function/provide/Counter.dart';

class YProvideState extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          children: <Widget>[
            Number(),
            MyButton()
          ],
        ),
      ),
    );
  }
}


class Number extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(top: 200),
      //Provide 绑定事件
      child: Provide<Counter>(
        builder: (context, child, counter) {
          return Text(
              '${counter.value}',
            style: Theme.of(context).textTheme.display1,
          );
        },
      ),
    );
  }
}


class MyButton extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: RaisedButton(onPressed: () {
        Provide.value<Counter>(context).increment();
      }, child: Text("递增"),),
    );
  }
}

